package com.boarsoft.boar.message.demo;

import org.apache.activemq.command.ActiveMQTextMessage;
import org.apache.activemq.command.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.boarsoft.common.util.JsonUtil;
import com.boarsoft.message.amq.adapter.AmqMsgConverter;

/**
 * 此类主要用于将拦截到的ActiveMQ消息转换为内部Message
 * 
 * @author Mac_J
 *
 */
public class AmqJsonMsgConverter implements AmqMsgConverter {
	private static final Logger log = LoggerFactory.getLogger(AmqJsonMsgConverter.class);

	@Override
	public com.boarsoft.message.bean.Message convert(Message am) throws Exception {
		ActiveMQTextMessage tm = (ActiveMQTextMessage) am;
		String s = tm.getText();
		log.debug("Received activemq text message: {}", s);
		return JsonUtil.parseObject(s, com.boarsoft.message.bean.Message.class);
	}

	@Override
	public Message convert(com.boarsoft.message.bean.Message m) throws Exception {
		return null;
	}
}
